<template>
	<view>
		<tab @switchStatus="switchStatus"/>
		<block v-if="isHasDataFlag">
			<list :focType="focType" :focList="focList" @goDetInfo="goDetInfo"/>
			<loading-view :loading="loading"></loading-view>
		</block>
		<block v-else-if="isHasDataFlag == false">
			<no-data></no-data>
		</block>
	</view>
</template>

<script>
	import Tab from './components/Tab'
	import List from './components/List'
	import { getMyFocus } from '@/api/mine/index'
	export default {
		components:{
			Tab,
			List
		},
		data(){
			return{
				focType:'zxs',
				focList:[],
				nowPage:1,
				loading:false,
				isHasDataFlag:null,
				isRefreshFlag:false
			}
		},
		onLoad(){
			this.loadMyFocus();
		},
		onPullDownRefresh : function(){
			this.initParams();
			uni.stopPullDownRefresh();
		},
		onReachBottom : function(){
			if( !this.loading ){
				this.loadMyFocus();
			}
		},
		onShow(){
			if(this.isRefreshFlag){
				this.initParams();
			}
		},
		onHide(){
			this.isRefreshFlag = false;
		},
		methods:{
			goDetInfo(index){
				if(this.focType == 'zxs'){
					var userId = this.focList[index].zxsUserId;
					uni.navigateTo({
						url:'../../subIndex/zxsDet/zxsDet?userId=' + userId + '&currPage=zxsFocPage'
					})
				}else{
					var ogzId = this.focList[index].ogzId;
					uni.navigateTo({
						url:'../../subIndex/ogzDet/ogzDet?ogzId=' + ogzId + '&currJumpPage=ogzFocPage'
					})
				}
			},
			loadMyFocus(){
				let { nowPage,focList } = this;
				this.loading = true;
				var field = { type:this.focType,page:this.nowPage,limit:this.limit };
				getMyFocus(field).then(res=>{
					//console.log(res)
					nowPage += 1;
					focList.push( ...res.data.datas );
					this.focList = focList;
					this.nowPage = nowPage;
					this.loading = false;
					this.isHasDataFlag = true;
				}).catch(err=>{
					//console.log(err)
					this.loading = false;
					this.isHasDataFlag=false;
				});
			},
			switchStatus(type){
				this.focType = type;
				this.initParams();
			},
			initParams(){
				this.nowPage = 1;
				this.loading = false;
				this.focList = [];
				this.loadMyFocus();
			}
		}
	}
</script>

<style lang='scss'>
	page{
		background: $pss-bg-primary;
		margin-top: 110rpx;
	}
</style>